<template>
  <div class="regist">
    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" v-loading="loading" :inline="true">
      <h3 class="title">用户注册</h3>
        <el-form-item label="用户名" prop="username">
        <el-input
          v-model="loginForm.username"
          placeholder="请输入用户名"
          clearable
          size="small"
          style="margin-left:11px;width: 240px"
        />
      </el-form-item>
     <el-form-item label="密 码" prop="password">
        <el-input
          v-model="loginForm.password"
          placeholder="请输入密码"
          type="password"
          clearable
          size="small"
          style="margin-left:21px;width: 240px"
        />
      </el-form-item>
       <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="loginForm.phone"
          placeholder="请输入手机号码"
          clearable
          size="small"
          style="margin-left:13px;width: 240px"
        />
      </el-form-item>
         <!-- <el-form-item label="性 别" prop="sex">
        <el-input
          v-model="loginForm.sex"
          placeholder="请选择性别"
          clearable
          size="small"
          style="margin-left:22px;width: 240px"
        />
      </el-form-item> -->
      <el-form-item label="性 别：" prop="sex">
        <el-select v-model="loginForm.sex" placeholder="性别" clearable>
            <el-option
                v-for="item in this.sexList"
                :key="item.id"
                :label="item.sex"
                :value="item.id"
                style="margin-left:22px;width: 240px"
              ></el-option>
       
        </el-select>
      </el-form-item>
      <el-form-item label="真实姓名" prop="realname">
        <el-input
          v-model="loginForm.realname"
          placeholder="请输入真实姓名"
          clearable
          size="small"
          style="width: 240px"
        />
      </el-form-item>
      <el-form-item label="公司地址" prop="company">
        <el-input
          v-model="loginForm.company"
          placeholder="请输入公司地址"
          clearable
          size="small"
          style="width: 240px"
        />
      </el-form-item>
    
      <el-form-item style="width:100%">
          
        <el-button
          :loading="loading"
          size="medium"
          type="primary"
          style="margin-left:80px;"
          @click="submitForm"
        >
          注册
        </el-button>
      <router-link  to="/login" style="margin-left:30px;color: #341e97;" >已注册，去登录>></router-link>
      </el-form-item>
    </el-form>
    <!--  底部  -->
    <!-- <div class="el-login-footer">
      <span>Copyright © 2018-2019 ruoyi.vip All Rights Reserved.</span>
    </div> -->
  </div>
</template>

<script>

import { regist } from '@/api/register'

export default {  
  data() {
    return {
      loginForm: {
        company: "",
        username: "",
        password: "",
        sex: null,
        phone: "",
        realname: ""
      },
      sexList:[
          {sex: '男', id: 1},
          {sex: '女', id: 2}
      ],
      loginRules: {
        username: [
          { required: true, trigger: "blur", message: "用户名不能为空" }
        ],
        password: [
          { required: true, trigger: "blur", message: "密码不能为空" }
        ],
        company: [
          { required: true, trigger: "blur", message: "公司不能为空" }
        ],
        sex: [
          { required: true, trigger: "blur", message: "性别不能为空" }
        ],
        phone: [
          { required: true, trigger: "blur", message: "手机不能为空" }
        ],
        realname: [
          { required: true, trigger: "blur", message: "姓名不能为空" }
        ]
      },
      loading: false,
      redirect: undefined
    };
  },
  created() {
  },
  methods: {
    submitForm () {
      let _this = this
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.loading = true
          regist(this.loginForm).then(data => {
            if (data.errno === 0) {
              _this.$message.success(data.errmsg)
              _this.$router.push('/login')
             
            } else {
              _this.$message.error(data.errmsg)
              _this.loading = false
            }
          }).catch(e => {
            _this.loading = false
          })
        } else {
          return false
        }
      })
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">
.regist {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-image: url("../../assets/image/login-background.jpg");
  background-size: cover;
}
.title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #707070;
}

.login-form {
  border-radius: 6px;
  background: #ffffff;
  width: 400px;
  padding: 25px 25px 5px 25px;
  .el-input {
    height: 38px;
    input {
      height: 38px;
    }
  }
  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 2px;
  }
}
.login-tip {
  font-size: 13px;
  text-align: center;
  color: #341e97;
}
.login-code {
  width: 33%;
  height: 38px;
  float: right;
  img {
    cursor: pointer;
    vertical-align: middle;
  }
}
.el-login-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}
.login-code-img {
  height: 38px;
}
</style>
